package com.douqu.game.core.entity.ext;

import com.bean.core.buffer.ByteBuffer;
import com.douqu.game.core.entity.WorldInfo;
import com.douqu.game.core.entity.sprite.Player;

/**
 * @author wangzhenfei
 *         2017-09-27 9:39
 *         竞技场信息
 */
public class ArenaInfo extends ExtInfo {

    /**
     * 自己的竞技场名次
     */
    private int mArenaRank;

    /**
     * 上一次领取奖励时间
     */
    private long lastRewardTime;

    /**
     * 当天挑战次数
     */
    private int todayChallengeTimes;

    public ArenaInfo(Player player, WorldInfo worldInfo) {
        super(player, worldInfo);
    }



    @Override
    public void writeTo(ByteBuffer buffer) {
        buffer.writeShort(mArenaRank);
        buffer.writeLong(lastRewardTime);
        buffer.writeByte(todayChallengeTimes);
        buffer.writeInt(0);//备用
    }

    @Override
    public void loadFrom(ByteBuffer buffer) {
        mArenaRank = buffer.readShort();
        lastRewardTime = buffer.readLong();
        todayChallengeTimes = buffer.readByte();
        buffer.readInt();
    }

    /**
     * 重置挑战次数
     */
    public void resetChallengeTimes(){
        todayChallengeTimes = 0;
    }


    /**
     * 挑战次数 -1
     */
    public void reduceChallengeTimes(){
        todayChallengeTimes -= 1;
    }

    /**
     * 是否可以挑战
     */
    public boolean isChallengeTimesEnough(){
        return todayChallengeTimes > 5;
    }


    public int getmArenaRank() {
        return mArenaRank;
    }

    public void setmArenaRank(int mArenaRank) {
        this.mArenaRank = mArenaRank;
    }

    public long getLastRewardTime() {
        return lastRewardTime;
    }

    public void setLastRewardTime(long lastRewardTime) {
        this.lastRewardTime = lastRewardTime;
    }

}
